﻿using System;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.UI;

namespace Terraria.ModLoader.UI
{
	// Token: 0x02000288 RID: 648
	internal sealed class UILoaderAnimatedImage : UIElement
	{
		// Token: 0x06001A58 RID: 6744 RVA: 0x00428D0C File Offset: 0x00426F0C
		public UILoaderAnimatedImage(float left, float top, float scale = 1f)
		{
			this.backgroundTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.LoaderBG.png"));
			this.loaderTexture = Texture2D.FromStream(Main.instance.GraphicsDevice, Assembly.GetExecutingAssembly().GetManifestResourceStream("Terraria.ModLoader.UI.Loader.png"));
			this.scale = scale;
			this.Width.Set(200f * scale, 0f);
			this.Height.Set(200f * scale, 0f);
			this.HAlign = left;
			this.VAlign = top;
		}

		// Token: 0x06001A59 RID: 6745 RVA: 0x00428DAC File Offset: 0x00426FAC
		protected override void DrawSelf(SpriteBatch spriteBatch)
		{
			int num = this.frameTick + 1;
			this.frameTick = num;
			if (num >= 5)
			{
				this.frameTick = 0;
				num = this.frame + 1;
				this.frame = num;
				if (num >= 16)
				{
					this.frame = 0;
				}
			}
			CalculatedStyle dimensions = base.GetDimensions();
			if (this.withBackground)
			{
				spriteBatch.Draw(this.backgroundTexture, new Vector2((float)((int)dimensions.X), (float)((int)dimensions.Y)), new Rectangle?(new Rectangle(0, 0, 200, 200)), Color.White, 0f, new Vector2(0f, 0f), this.scale, SpriteEffects.None, 0f);
			}
			spriteBatch.Draw(this.loaderTexture, new Vector2((float)((int)dimensions.X), (float)((int)dimensions.Y)), new Rectangle?(new Rectangle(200 * (this.frame / 8), 200 * (this.frame % 8), 200, 200)), Color.White, 0f, new Vector2(0f, 0f), this.scale, SpriteEffects.None, 0f);
		}

		// Token: 0x0400178E RID: 6030
		public bool withBackground;

		// Token: 0x0400178F RID: 6031
		public int frameTick;

		// Token: 0x04001790 RID: 6032
		public int frame;

		// Token: 0x04001791 RID: 6033
		private float scale;

		// Token: 0x04001792 RID: 6034
		public const int maxFrames = 16;

		// Token: 0x04001793 RID: 6035
		public const int maxDelay = 5;

		// Token: 0x04001794 RID: 6036
		private readonly Texture2D backgroundTexture;

		// Token: 0x04001795 RID: 6037
		private readonly Texture2D loaderTexture;
	}
}
